﻿package mortal.game.view.common.guide.view
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.mainUI.shortcutbar.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;

    public class AutoGuideNewSkill extends AutoGuideNewFunc
    {
        private var _skillInfo:SkillInfo;
        private var _txtSkillName:GTextFiled;
        private var _bmpTypeBg:GBitmap;
        private var _bmpType:GBitmap;
        public static var instance:AutoGuideNewSkill = new AutoGuideNewSkill;
        public static var isShowing:Boolean = false;

        public function AutoGuideNewSkill()
        {
            super(false);
            return;
        }// end function

        override protected function setChangebleUI() : void
        {
            _bmpTitle = UIFactory.gImageBitmap(null, 167, 38, this);
            LoaderHelp.setBitmapdata("FuncOpen_Skill.swf", _bmpTitle);
            _bmpClick = UIFactory.gImageBitmap(null, 346, 84, this);
            LoaderHelp.setBitmapdata("FuncOpen_ClickGet.swf", _bmpClick);
            var _loc_1:* = GlobalStyle.textFormatHuang;
            _loc_1.size = 18;
            _loc_1.color = 15521313;
            this._txtSkillName = UIFactory.gTextField("", 88, 88, 120, 30, this, _loc_1);
            this._bmpTypeBg = UIFactory.gBitmap(ImagesConst.PetNameBg, 62, 118, this);
            this._bmpType = UIFactory.bitmap(null, 101, 125, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bmpTypeBg.dispose(param1);
            this._bmpTypeBg = null;
            this._txtSkillName.dispose(param1);
            this._txtSkillName = null;
            this._bmpType.dispose(param1);
            this._bmpType = null;
            return;
        }// end function

        public function set skillInfo(param1:SkillInfo) : void
        {
            var panelGot:Function;
            var $skillInfo:* = param1;
            panelGot = function () : void
            {
                if (isDisposed)
                {
                    return;
                }
                if (_skillInfo.tSkill.triggerType == ESkillTriggType._ESkillTriggBeAttack || _skillInfo.tSkill.triggerType == ESkillTriggType._ESkillTriggBorn)
                {
                    _bmpType.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_FZ);
                    _bmpType.x = 52;
                }
                else if (_skillInfo.tSkill.rangeType == ESkillRangeType._ESkillRangeTypeSingle)
                {
                    _bmpType.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_DTGJ);
                }
                else
                {
                    _bmpType.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_QTGJ);
                }
                return;
            }// end function
            ;
            _icon.source = $skillInfo.tSkill.skillIcon.toString() + ".jpg";
            this._skillInfo = $skillInfo;
            super.setLabel(null, $skillInfo.tSkill.skillIcon.toString() + ".jpg", Language.getStringByParam(20718, this._skillInfo.skillName));
            this._txtSkillName.text = "【" + this._skillInfo.skillName + "】";
            LoaderHelp.addResCallBack(ResFileConst.skillPanel, panelGot);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            isShowing = true;
            super.show(Global.stage.stageWidth / 2 - 278, Global.stage.stageHeight - 310);
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            isShowing = false;
            return;
        }// end function

        override protected function clickIconHandler(event:MouseEvent) : void
        {
            var skillInfo:SkillInfo;
            var targetItem:ShortcutBarItem;
            var start:int;
            var afterFlyTo:Function;
            var obj:Object;
            var info:SkillInfo;
            var evt:* = event;
            afterFlyTo = function () : void
            {
                if (targetItem == null)
                {
                    return;
                }
                (GameController.shortcut.view as ShortcutBar).updateShortcutSource(targetItem.pos, skillInfo);
                targetItem = null;
                if (start != 11)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.SkillUpgradeReq, skillInfo.skillId));
                }
                return;
            }// end function
            ;
            var mx:* = this.mouseX;
            var my:* = this.mouseY;
            if (evt != null && (mx < 0 || my < 0 || mx > 517 || my > 190))
            {
                return;
            }
            skillInfo = this._skillInfo;
            if (skillInfo == null)
            {
                this.hide();
                return;
            }
            if (skillInfo.isBeAttackSkill)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SkillUpgradeReq, skillInfo.skillId));
                this.hide();
                return;
            }
            var items:* = (GameController.shortcut.view as ShortcutBar).getAllItems();
            var item:* = GameController.shortcut.getSkillsShortcutItem(skillInfo);
            if (item != null)
            {
                this.hide();
                return;
            }
            start;
            var skillId:* = skillInfo.skillId;
            if (skillId == GameConst.SkillMount || skillId == GameConst.JPSkillId || skillId == GameConst.RollingSkillId || skillId == GameConst.SkillThing)
            {
                start;
            }
            var i:* = start;
            while (i < items.length)
            {
                
                item = items[i];
                if (item == null || item.dragSource != null)
                {
                    info = item.dragSource as SkillInfo;
                    if (info != null && info.skillId == skillId)
                    {
                        if (info.learned)
                        {
                            return;
                        }
                        targetItem = item;
                        break;
                    }
                }
                else
                {
                    obj = Cache.instance.shortcut.getData(i);
                    if (obj != null)
                    {
                        if (obj["t"] == CDDataType.skillInfo && obj["v"] == skillId)
                        {
                            targetItem = item;
                            break;
                        }
                    }
                    else
                    {
                        targetItem = item;
                        break;
                    }
                }
                i = (i + 1);
            }
            if (targetItem == null)
            {
                this.hide();
                return;
            }
            if (i >= 11 && GameController.shortcut.shortcutBar != null)
            {
                GameController.shortcut.shortcutBar.showItem(i);
            }
            var fromValue:* = ShortcutBarUtil.parseValue(skillInfo);
            if (!Cache.instance.shortcut.hasTypeValue(CDDataType.skillInfo, fromValue))
            {
                Cache.instance.shortcut.addShortCut(targetItem.pos, CDDataType.skillInfo, fromValue);
                Cache.instance.shortcut.save();
            }
            var p:* = _icon.localToGlobal(GameConst.yellowPoint);
            var tp:* = targetItem.localToGlobal(GameConst.yellowPoint);
            FlyToNavbarTool.flyToAnyPoint(_icon.bitmapdata, p, tp, afterFlyTo, 0, 0, false, targetItem.width / 60, targetItem.height / 60, true, null);
            this.hide();
            GameController.cd.registerSkillCD(skillInfo);
            GameController.cd.registerBasicSkillCD();
            if (hasCloseTaskWin && GuideController.shouldResumeToTaskAfterGuide())
            {
                hasCloseTaskWin = false;
                GameController.guide.resumeToTask();
            }
            return;
        }// end function

    }
}
